Repository navigation
Write named tuples, complex numbers, irrationals, and non-string keys as YAML values - #279
Merged
Merged
Conversation
…keys load back Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… as YAML values Named tuples, complex numbers, and irrationals fell through to string(), and keys other than text used string(k). They loaded back as Julia text, and a tuple key holding ': ' gave YAML that didn't load. Named tuples are now written as mappings, complex numbers as a re/im mapping (JSON.jl's form), irrationals as the nearest float, scalar keys as their values would be, and collection keys as explicit '?' keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #279 +/- ##
==========================================
+ Coverage 91.48% 91.64% +0.15%
==========================================
Files 15 15
Lines 1715 1735 +20
==========================================
+ Hits 1569 1590 +21
+ Misses 146 145 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A Pair key was written as "1: 2: 3", which doesn't load. Treating Pair as a mapping writes it with an explicit '?' key when it is a key and as a nested mapping when it is a value, and both load back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
YAML.writewrote named tuples, complex numbers, irrationals such asπ, and dictionary keys that aren't text as Julia source text. They loaded back as strings:(a = 1,)became"(a = 1,)", and the keyInfbecame"Inf". A tuple key holding": "gave YAML that didn't load at all.What changed
reandim, the shape JSON.jl writes. YAML has no complex type, and the writer can't emit tags.Infbecomes.infand1//2becomes0.5. A nonempty collection key (tuple, vector, set, dict, named tuple, complex) is written as an explicit?key, soDict((1, 2) => 3)loads back asDict([1, 2] => 3).For example,
YAML.yaml((name = "a", pos = 1 + 2im, k = Dict((1, 2) => pi)))now gives:Scope
nothing, andmissingkeys are written as before. Round 1's corpus of 20,000 values of the other supported types writes byte-identical output.Tradeoffs
"1 + 2im". That keeps Julia's syntax, but no YAML reader loads it as a number. The mapping keeps both parts numeric in every reader.Blast Radius
SequencetoUnion{AbstractArray,Tuple,AbstractSet}, whichstarts_blockuses.Verification
yaml, and js-yaml load all 21 written named-tuple, complex, and irrational values (top level, dict value, list item) as the expected values. Psych reads all 12 written key forms as typed keys (Infinity,[1, 2],{"a"=>1}, and so on).Pkg.test()passes on Julia 1.12.6 and on Julia 1.0.5 (Docker).🤖 Generated with Claude Code